using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SideShow.Scf.ObjectModel;
using SideShowClient;

namespace PocketPCSideShowClient
{
    public partial class ScfUserControl : UserControl
    {
        private Dictionary<uint, ScfContextMenu> _contextMenus = new Dictionary<uint, ScfContextMenu>();
        
        private ScfNavigator _navigator;
        private ScfObject _scfObject;

        public ScfUserControl()
        {
            InitializeComponent();
        }

        public ScfUserControl(ScfNavigator navigator)
        {
            _navigator = navigator;
            InitializeComponent();
        }

        protected virtual void BindData()
        {
        }

        public ScfNavigator Navigator
        {
            get { return _navigator; }
        }

        public ScfObject ScfObject
        {
            get { return _scfObject; }
            set
            {
                if (_scfObject != value)
                {
                    _scfObject = value;
                    BindData();
                }
            }
        }

        protected ScfContextMenu GetContextMenu(uint contentId, ScfMenuItem menuItem)
        {
            ScfContextMenu scfCtx = null;
            if (!_contextMenus.TryGetValue(contentId, out scfCtx))
            {
                SideShow.Scf.Contents.ScfContent cnt = Navigator.GetContent(contentId) as SideShow.Scf.Contents.ScfContent;
                if (cnt != null)
                {
                    ScfMenu mnu = cnt.ScfDocument.Body as ScfMenu;
                    if (mnu != null)
                    {
                        scfCtx = new ScfContextMenu(mnu, menuItem, this);
                        _contextMenus.Add(contentId, scfCtx);
                    }
                }
            }
            return scfCtx;
        }

    }
}
